package test.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import test.interceptor.MyInterceptor;

@Configuration
@ComponentScan({"test.controller","test.interceptor"})
//要使WebMvcConfigurerAdapter生效，需要开启此配置
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    @Autowired
    MyInterceptor myInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(myInterceptor).addPathPatterns("/index");
    }
}
